package com.example.orderanduserbeta;


import com.alibaba.fastjson.JSON;
import com.domain.Orderinfo;
import com.service.OrderinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
//@ComponentScan("com.service")
//@MapperScan("com.service")
public class HelloController {
    //@Qualifier("orderservice")
    @Autowired
    private OrderinfoService omp;
    @RequestMapping("/order")
    public String order(){


        List<Orderinfo> list = omp.selectByAll();

        Set<Integer> v=new HashSet();
        HttpTools ht=new HttpTools();
        List lists=new ArrayList();
        for (Orderinfo orderinfo : list) {
            Integer uud = orderinfo.getUud();
            v.add(uud);
            String userJson = ht.sendPost("http://localhost:8081/user/" + orderinfo.getUud(),null);
           // System.out.println(userJson);
            System.out.println(orderinfo.getUud()+","+orderinfo.getType()+","+userJson);
            lists.add(orderinfo.getUud()+","+orderinfo.getType()+","+userJson);


        }

        //String json= JSON.toJavaObject(lists);

//        String jsonStr= JSONObject.toJSONString(userJson);

        ///
//        JSONObject object = JSONObject
//                .parseObject(userJson);
//
//        System.out.println(jsonStr);
//        //list
//        List<Integer> integers = JSON.parseArray(object.getJSONArray("userid").toJSONString(),Integer.class);
//        integers.forEach(System.out::println);

        return lists.toString();


    }

    @RequestMapping("/hello")
    public String hello(){

        List<String> list=  Arrays.asList("a", "b");
        Map<String,Object> mp=new HashMap<>();
        mp.put("1","A");
        mp.put("2","B");
        mp.put("3",list);
        String json= JSON.toJSONString(mp);
        System.out.println(json);
        return json;

    }

}
